package com.kichina.galaxy.dev.tools.init;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class InitHandler implements CommandLineRunner {

    private final List<IInit> initList;

    public InitHandler(List<IInit> initList) {
        this.initList = initList;
    }

    @Override
    public void run(String... args) throws Exception {
      try {
          for (IInit iInit : initList) {
           try {
               iInit.init();
           }catch (Exception e){
               log.error("初始化[{}]异常!",iInit.getClass().getName(),e);
           }
          }
      }catch (Exception e){
        log.error("初始化异常!",e);
      }
    }
}
